<template>
<div class="window" v-show="m" @mouseleave="hideM">
  <div class="goods_box" >
    <div class="mini_goods" id="mini"
    v-for="(m,index) in cartgoods" :key="index">
    <div>
      <img :src="m.thumb_url" alt="">
    </div>
    <div class="m_name">{{m.goods_name}}</div>
    <div class="m_price">{{(m.price / 100) | moneyFormat}}×<span>{{m.buy_count}}</span></div>
    </div>
    <div class="nothing" v-show="noGoods()">
      购物车中还没有商品，赶紧登录选购吧！
    </div>
  </div>
  
  <div class="mini_footer">
    <button @click="goShopCar">购物车</button>
  </div>
</div>
</template>

<script>
import {mapState} from 'vuex'
export default {
    name:'MiniWindow',
    data() {
      return {
        m:'',
        nothing:false
      }
    },
    created() {
      this.$bus.$on('showWindow',showM=>{
        this.m = showM
      })
    },
    computed: {
      ...mapState(["userInfo","cartgoods"]),
    },
    methods: {
      noGoods(){
        if (document.getElementById("mini")) {
          return false
        }else{
          return true
        }
      },
      goShopCar(){
          this.$router.replace('/shopcar');
        },
      hideM(){
        this.m = !this.m
        this.$bus.$emit('hideM',this.m)
      }
      },
}
</script>

<style scoped>
  .window{
    width: 302px;
    height: 425px;
    position: absolute;
    border: 1px solid red;
    background-color: #fff;
    margin-top: -86px;
    margin-left: 67%;
    z-index: 10;
  }
  .goods_box{
    overflow: auto;
    height: 385px;
    width: 300px;
  }
  .mini_goods{
    width: 268px;
    height: 50px;
    margin: 10px 6px;
    font-size: 12px;
    color: #666;
    border-bottom: 2px solid #f5f5f5;
  }
  .mini_goods div{
    float: left;
  }
  .mini_goods img{
    width: 50px;
    height: 50px;
  }
  .m_name{
    width: 100px;
    height: 40px;
    margin: 5px;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    text-overflow: ellipsis;
  }
  .m_price{
    margin-left: 40px;
    font-weight: 700;
  }
  .nothing{
    width: 100%;
    text-align:center;
    font-size: 14px;
    color: #666;
    margin:180px auto;
  }
  .mini_footer{
    width: 300px;
    height: 37px;
    background-color: #f5f5f5;
    position: fixed;
  }
  .total{
    margin-left: 5px;
    font-size: 12px;
    color: #666;
    font-weight: 700;
  }
  button{
    float: right;
    margin:6px 24px 6px 0;
    outline: none;
    border: none;
    padding: 5px;
    border-radius: 5px;
    background-color: #e1251b;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
  }
</style>